package kr.moiba.board.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kr.moiba.board.dao.BoardDao;
import kr.moiba.board.domain.Board;
import kr.moiba.board.service.BoardSvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Lee Youngho
 *
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT ,rollbackFor = {Exception.class} ,readOnly = false)
public class BoardSvcImpl implements BoardSvc {

	@Autowired
	BoardDao boardDao;
	
	public BoardSvcImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Board> findbyList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<Board>) (boardDao.SelectList(condition));
	}

	public Map<String, Object> findbyListPaging(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("boardList", (List<Board>) (boardDao.SelectList(condition)));
		resultMap.put("boardListTotalCnt", (Integer) (boardDao.SelectListTotalCnt(condition)));
		
		return resultMap;
	}

	@Override
	public Board findby(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub

		Integer idx = (Integer)condition.get("idx");
		//조회수 더하기
		int addViewCntResult = boardDao.updateViewCnt(condition);
		
		return boardDao.select(idx);
	}

	@Override
	public Board add(Board board) throws Exception {
		// TODO Auto-generated method stub
		Board result = boardDao.insert(board);
		
		return result;
	}

	@Override
	public Board modify(Board board) throws Exception {
		// TODO Auto-generated method stub
		return boardDao.update(board);
	}

	@Override
	public int remove(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return boardDao.delete(condition);
	}

}